﻿using Seagull.BarTender.Print;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace bartlibtest
{
    internal class Program
    {
        static Engine engine = null; // The BarTender Print Engine
        static LabelFormatDocument document = null; // The currently open Format
        static void Main(string[] args)
        {
            try
            {
                Printers printers = new Printers();
                foreach (Printer printer in printers)
                {
                    Console.WriteLine(printer.PrinterName);
                }
                engine = new Engine(true);
                document = engine.Documents.Open("btw文件名");
                //测试导出，ImageType有很多类型可选，都试试
                document.ExportImageToFile("pdf文件名", ImageType.EPS, ColorDepth.ColorDepth24bit,
   new Resolution(600), OverwriteOptions.Overwrite);
                //测试打印，如果打印机名设置为虚拟pdf打印机 看看效果
                document.PrintSetup.PrinterName = "打印机名";

                Messages messages;
                int waitForCompletionTimeout = 10000; // 10 seconds
                Result result = document.Print("bartlibtest", waitForCompletionTimeout, out messages);
                foreach (Message message in messages)
                {
                    Console.WriteLine(message.Text);
                }
            }
            catch (PrintEngineException ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

        }
    }
}
